﻿using NORM.Entity;
using NORM.SQLObject;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace NORM.Demo
{
    public partial class Sqlite迸发测试 : Form
    {
        public Sqlite迸发测试()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Threading.Thread[] ths = new System.Threading.Thread[] {

                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test)),
                new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(test))

            };

            for(int i=0;i<ths.Length;i++)
            {
                ths[i].IsBackground = true;             
            }

            for (int i = 0; i < ths.Length; i++)
            {
                ths[i].Start(i);
            }
               
        }

        private void test(object threadId)
        {
            using (var db = NORM.DataBase.DataBaseFactory.Default)
            {
                OQL tmp = null;
                try
                {
                    Models.T_Category model = new Models.T_Category();
                    //OQL oql = OQL.From(model).Where(w => w.Compare(model.Code, "!=", "")
                    //    & w.Compare(model.DeleteSign, "=", 0)
                    //    & w.Compare(model.Name, "IS NOT", DataValue.DBNull)
                    //    & w.Compare(model.ID, ">", 1, "OR"))
                    //    .Select(() =>
                    //    {
                    //        return new { model.Describ, model.DeleteSign, model.Code };
                    //    }).End;

                    Models.T_Accounts model2 = new Models.T_Accounts();

                    OQL oql = OQL.From(model2).LeftJoin(model).ON(model2.Category, model.ID).Where(model2.EncryptSign, 1)
                        .Select(() => {
                            return new { model2.DeleteSign, model2.CreateDate, model2.Describ, model.Name, model.OrderIndex };
                        }).End;

                    tmp = oql;

                    DataTable dt = db.QueryTable(oql);
                    var list = EntityQuery<Models.T_Category>.Instance.QueryToList(oql, db);

                    string name = list.Count > 0 ? list[0].Name : "未获取到";

                    NORM.Logger.LoggerHelper.Debug(threadId + " " + name + " 执行成功", "Sqlite迸发测试");

                }
                catch (Exception ex)
                {
                    NORM.Logger.LoggerHelper.Debug(ex.Message, "Sqlite迸发测试");
                }
            }
        }
    }
}
